package com.woniuxy.woniufp.trade.controller;

import com.woniuxy.woniufp.common.model.dto.trade.BorrowRecordDTO;
import com.woniuxy.woniufp.common.model.dto.trade.BorrowRecordQuery;
import com.woniuxy.woniufp.common.model.result.Result;
import com.woniuxy.woniufp.common.model.vo.trade.BorrowRecordVo;
import com.woniuxy.woniufp.common.model.vo.trade.Pages;
import com.woniuxy.woniufp.trade.service.IBorrowRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.MessagingAdviceBean;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "交易中心操作")
public class TradeController {

    @Autowired
    IBorrowRecordService borrowRecordService ;

    @ApiOperation("借款申请")
    @PostMapping("/trade/borrow/add")
    public Result
    addBorrowRecord(@RequestBody BorrowRecordDTO borrowRecordDTO) {
        borrowRecordService.addBorrowRecord(borrowRecordDTO);
        return Result.ok();
    }

    @ApiOperation("借款记录查询")
    @PostMapping("/trade/borrow/query")
    public Result<Pages<BorrowRecordVo>> queryBorrowRecord(
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "2") Integer pageSize,
            @RequestBody BorrowRecordQuery borrowRecordQuery) {
        Pages<BorrowRecordVo> pages =
                borrowRecordService.queryBorrowRecord(pageNum,pageSize,borrowRecordQuery);
        return Result.ok(pages);
    }

    @PutMapping("/trade/borrow/status")
    @ApiOperation("同步借款记录")
    public Result veriyStatus(Integer approveStatus ,Long borrowRecordId){
        String message = borrowRecordService.verifyStatus(approveStatus,borrowRecordId);
        return Result.ok(message);
    }
}
